package com.czp.role.action;

import com.czp.framework.action.BaseActionSupport;
import com.czp.framework.exception.IServiceException;
import com.czp.role.model.RelationMenu;
import com.czp.role.model.Role;
import com.czp.role.service.IRoleService;

/**
 * 【环 境】：J2SE 1.7
 * @author   柴志鹏	CHAIZP@GMAIL.COM
 * @version  version 1.0
 * @since    2014-6-12
 */
public class RoleAction extends BaseActionSupport {
	private static final long serialVersionUID = 7441250485853506486L;
	private IRoleService roleService;
	private Role role;
	
	/** 
	 * 【描 述】：获取角色列表
	 */
	public void getRoleList() {
		try {
			Role role = new Role();
			role.setStart(Integer.parseInt(request.getParameter("start")));
			role.setLimit(Integer.parseInt(request.getParameter("limit")));
			role.setRoleName(request.getParameter("roleName"));
			this.responseOutPrint(
					roleService.getRoleList(role));
		} catch(Exception e) {
			throw new IServiceException(this.getClass() + "getRoleList", e);
		}
	}
	
	/** 
	 * 【描 述】：添加、修改、删除批处理
	 */
	public void roleOperator() {
		try {
			String jsonData = request.getParameter("jsonData");
			this.responseOutPrint(
					"{success:"+ roleService.roleOperator(jsonData) +"}");
		} catch(Exception e) {
			throw new IServiceException(this.getClass() + "roleOperator", e);
		}
	}
	
	/** 
	 * 【描 述】：根据角色ID查询授权菜单项
	 */
	public void getRelationMenuList() {
		try {
			Role role = new Role();
			role.setStart(Integer.parseInt(request.getParameter("start")));
			role.setLimit(Integer.parseInt(request.getParameter("limit")));
			role.setId(request.getParameter("roleId"));
			role.setMenuName(request.getParameter("menuName"));
			this.responseOutPrint(
					roleService.getRelationMenuList(role));
		} catch(Exception e) {
			throw new IServiceException(this.getClass() + "getRelationMenuList", e);
		}
	}
	
	/** 
	 * 【描 述】：根据角色Id删除菜单关联项
	 */
	public void deleteRelationMenu() {
		try {
			String jsonData = request.getParameter("jsonData");
			this.responseOutPrint(roleService.deleteRelationMenu(jsonData));
		} catch(Exception e) {
			throw new IServiceException(this.getClass() + "deleteRelationMenu", e);
		}
	}
	
	/** 
	 * 【描 述】：授权或取消功能菜单
	 */
	public void relationMenuController() {
		try {
			String jsonData = request.getParameter("jsonData");
			this.responseOutPrint(
					roleService.relationMenuController(jsonData));
		} catch(Exception e) {
			throw new IServiceException(this.getClass() + "relationMenuController", e);
		}
	}
	
	/** 
	 * 【描 述】：查询功能菜单与授权情况
	 */
	public void queryRelationMenu() {
		try {
			RelationMenu relMenu = new RelationMenu();
			relMenu.setRoleId(request.getParameter("roleId"));
			relMenu.setPid(request.getParameter("pid"));
			relMenu.setMenuType(request.getParameter("menuType"));
			this.responseOutPrint(
					roleService.queryRelationMenu(relMenu));
		} catch(Exception e) {
			throw new IServiceException(this.getClass() + "queryRelationMenu", e);
		}
	}

	/**
	 * 获取 roleService
	 * @return 返回 roleService
	 */
	public IRoleService getRoleService() {
		return roleService;
	}
	/**
	 * 设置 roleService
	 * @param 对roleService进行赋值
	 */
	public void setRoleService(IRoleService roleService) {
		this.roleService = roleService;
	}
	/**
	 * 获取 role
	 * @return 返回 role
	 */
	public Role getRole() {
		return role;
	}
	/**
	 * 设置 role
	 * @param 对role进行赋值
	 */
	public void setRole(Role role) {
		this.role = role;
	}
	
}
